package
{
import flash.display.*;

public class CornerTool extends MoveTool
{
	
	public function CornerTool()
	{
		super();
		this.keyCode=87;
	}
	
	override public function down():void{
		var p:Object=canvas.getClosePoint();
		if(p){
			var paths:Array=canvas.getPaths(p);
			if(paths.length>2||p.isColor||p.isControl)return;
			p.isCorner=!p.isCorner;
		}
	}
	
	override public function move():void{
		
	}
	
	override public function up():void{
	
	}
	
	override public function renderMouseMC(mouse_mc:Sprite):void{
		var p:Item=canvas.getClosePoint();
		canvas.removeChildren(mouse_mc);
		if(p){
			mouse_mc.addChild(getHandler(p));
		}
		
		var ps:Array=canvas.getCloseLine();
		
			if(ps.length==1){
				var pp:Object=canvas.getCloestPointOnPath(canvas.simpleMousePoint(),Path(ps[0]));
				if(pp!=null){
					mouse_mc.addChild(getHandler(pp));
					addPoint=new PointObj();
					addPoint.x=pp.x;
					addPoint.y=pp.y;
					targetLine=ps[0];
				}
			}else{
				addPoint=null;
			}
	}
	
	override public function drawPoints(points:Collection,point_pen:Graphics):void{
		//draw points 
		var itr:Iterator=new Iterator(points.toArray());
		var point:Object;
		point_pen.clear();
		point_pen.lineStyle(1,0x000000,1);
		var paths:Array;
		while(itr.hasNext()){
			point=itr.next();
			paths=canvas.getPaths(point);
			
			if(point.isHole||point.isColor||point.isControl||paths.length>2)continue;
			point_pen.drawRect(point.x-3,point.y-3,6,6);
		}
	}
	
}

}

